package code.rocky.chapter03;

public class Suggest34 {
    public static void main(String[] args) {
        SimpleServer s = new SimpleServer(1000);
    }
}

abstract class Server {

    public final static int DEFAULT_PORT = 4000;

    public Server() {
        int port = getPort();
        System.out.println("端口号: " + port);
    }

    protected abstract int getPort();
}

class SimpleServer extends Server {

    private int port = 100;

    public SimpleServer(int _port) {
        port = _port;
    }

    @Override
    protected int getPort() {
        return Math.random() > 0.5 ? port : DEFAULT_PORT;
    }
}
